import QtQuick 2.0
import DataMan 0.1
import "../utils.js" as Utils

Image {
	id: img
	property url normalImg: ""
	property url selectedImg: ""
	property bool showAni: false
	signal clicked()

	source: normalImg
	transformOrigin: Item.Center

	PropertyAnimation on scale{
		running: false
		id: inani
		duration: 100
		from: 1
		to: 0.85
	}

    PropertyAnimation on scale {
		running: false
	    id: outani
	    easing.amplitude: 1.15
	    duration: 400
	    from: 0.85
	    to: 1.0
	    easing.type: Easing.OutBounce
    }

	MouseArea {
		anchors.fill: parent
		acceptedButtons: Qt.LeftButton

		onClicked:  {
			if (DataMan.music)
				Utils.playEffect("button");
			parent.clicked();
		}
		onPressed: {
			if (showAni) {
				outani.stop()
				inani.start()
			}
			if (selectedImg != "")
				parent.source = selectedImg
		}
		onReleased: {
			if (selectedImg != "")
				parent.source = normalImg
			if (showAni) {
				inani.stop()
				outani.start()
			}
		}
	}
}

